package org.example.hengshengexam;

import java.util.ArrayList;
import java.util.List;

// 图书类
class Book {
    private String id;
    private String name;
    private String author;

    public Book(String id, String name, String author) {
        this.id = id;
        this.name = name;
        this.author = author;
    }

    // getter 和 setter 方法（略）
    public String getId() { return id; }
    public String getName() { return name; }
    public String getAuthor() { return author; }

    @Override
    public String toString() {
        return "图书ID：" + id + "，名称：" + name + "，作者：" + author;
    }
}

// 图书管理系统类
public class BookManagementSystem {
    private List<Book> books = new ArrayList<>();

    // 添加图书
    public void addBook(Book book) {
        books.add(book);
        System.out.println("添加图书成功：" + book);
    }

    // 删除图书
    public void removeBook(String id) {
        for (int i = 0; i < books.size(); i++) {
            if (books.get(i).getId().equals(id)) {
                books.remove(i);
                System.out.println("删除图书ID为" + id + "的图书成功");
                return;
            }
        }
        System.out.println("未找到ID为" + id + "的图书");
    }

    // 查询图书
    public void queryBook(String id) {
        for (Book book : books) {
            if (book.getId().equals(id)) {
                System.out.println("查询到图书：" + book);
                return;
            }
        }
        System.out.println("未找到ID为" + id + "的图书");
    }

    // 主方法测试
    public static void main(String[] args) {
        BookManagementSystem bms = new BookManagementSystem();
        bms.addBook(new Book("B001", "Java编程思想", "Bruce Eckel"));
        bms.queryBook("B001");
        bms.removeBook("B001");
        bms.queryBook("B001");
    }
}